home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / 74123.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  4KB  |  175 lines

  1. /*****************************************************************************
  2.  
  3.   74123 monoflop emulator - there are 2 monoflops per chips
  4.  
  5.   74123 pins and assigned interface variables/functions
  6.  
  7.     TTL74123_trigger_comp_w    [ 1] /1TR           VCC [16]
  8.     TTL74123_trigger_w        [ 2]  1TR        1RCext [15]
  9.       TTL74123_reset_comp_w    [ 3] /1RST         1Cext [14]
  10.     TTL74123_output_comp_r    [ 4] /1Q            1Q [13] TTL74123_output_r
  11.     TTL74123_output_r        [ 5]  2Q           /2Q [12] TTL74123_output_comp_r
  12.                              [ 6]  2Cext         /2RST [11] TTL74123_reset_comp_w
  13.                              [ 7]  2RCext       2TR [10] TTL74123_trigger_w
  14.                                [ 8]  GND          /2TR [9]  TTL74123_trigger_comp_w
  15.  
  16.     All resistor values in Ohms.
  17.     All capacitor values in Farads.
  18.  
  19.     Truth table:
  20.     R    A    B | Q  /Q
  21.     ----------|-------
  22.     L    X    X | L    H
  23.     X    H    X | L    H
  24.     X    X    L | L    H
  25.     H    L  _- |_-_ -_-
  26.     H  -_    H |_-_ -_-
  27.     _-    L    H |_-_ -_-
  28.     ------------------
  29.     A    = trigger_comp
  30.     B    = trigger
  31.     R    = reset_comp
  32.     L    = lo (0)
  33.     H    = hi (1)
  34.     X    = any state
  35.     _-    = raising edge
  36.     -_    = falling edge
  37.     _-_ = positive pulse
  38.     -_- = negative pulse
  39.  
  40.  *****************************************************************************/
  41.  
  42. #include "driver.h"
  43. #include "machine/74123.h"
  44.  
  45. struct TTL74123 {
  46.     const struct TTL74123_interface *intf;
  47.     int trigger;            /* pin 2/10 */
  48.     int trigger_comp;        /* pin 1/9 */
  49.     int reset_comp;            /* pin 3/11 */
  50.     int output;                /* pin 13/5 */
  51.     void *timer;
  52. };
  53.  
  54. static struct TTL74123 chip[MAX_TTL74123];
  55.  
  56.  
  57. static void set_output(int which, int data)
  58. {
  59.     chip[which].output = data;
  60.     chip[which].intf->output_changed_cb();
  61. }
  62.  
  63.  
  64. void TTL74123_config(int which, const struct TTL74123_interface *intf)
  65. {
  66.     if (which >= MAX_TTL74123) return;
  67.  
  68.     chip[which].intf = intf;
  69.  
  70.     /* all inputs are open first */
  71.     chip[which].trigger = 1;
  72.     chip[which].trigger_comp = 1;
  73.     chip[which].reset_comp = 1;
  74.     set_output(which, 1);
  75. }
  76.  
  77.  
  78. void TTL74123_unconfig(void)
  79. {
  80.     int i;
  81.  
  82.     for (i = 0; i < MAX_TTL74123; i++)
  83.     {
  84.         if (chip[i].timer)  timer_remove(chip[i].timer);
  85.     }
  86.  
  87.     memset(&chip, 0, sizeof(chip));
  88. }
  89.  
  90.  
  91. static void clear_callback(int which)
  92. {
  93.     struct TTL74123 *c = chip + which;
  94.  
  95.     c->timer = 0;
  96.     set_output(which, 0);
  97. }
  98.  
  99.  
  100. #define CHECK_TRIGGER(COND)                                                     \
  101.     {                                                                            \
  102.         if (COND)                                                                \
  103.         {                                                                        \
  104.             double duration = TIME_IN_SEC(0.68 * c->intf->res * c->intf->cap);    \
  105.                                                                                 \
  106.             if (c->timer)                                                        \
  107.                 timer_reset(c->timer, duration);                                \
  108.             else                                                                \
  109.             {                                                                    \
  110.                 set_output(which, 1);                                            \
  111.                 c->timer = timer_set(duration, which, clear_callback);            \
  112.             }                                                                    \
  113.         }                                                                        \
  114.     }
  115.  
  116. #define RESET                                                                    \
  117.     if (c->timer)                                                                \
  118.     {                                                                            \
  119.         timer_reset(c->timer, TIME_NOW);                                        \
  120.     }
  121.  
  122.  
  123. void TTL74123_trigger_w(int which, int data)
  124. {
  125.     struct TTL74123 *c = chip + which;
  126.  
  127.     /* trigger_comp=lo and rising edge on trigger (while reset_comp is hi) */
  128.     if (data)
  129.         CHECK_TRIGGER(!c->trigger_comp && !c->trigger && c->reset_comp)
  130.     else
  131.         RESET
  132.  
  133.     c->trigger = data;
  134. }
  135.  
  136.  
  137. void TTL74123_trigger_comp_w(int which, int data)
  138. {
  139.     struct TTL74123 *c = chip + which;
  140.  
  141.     /* trigger=hi and falling edge on trigger_comp (while reset_comp is hi) */
  142.     if (!data)
  143.         CHECK_TRIGGER(c->trigger && c->trigger_comp && c->reset_comp)
  144.     else
  145.         RESET
  146.  
  147.     c->trigger_comp = data;
  148. }
  149.  
  150.  
  151. void TTL74123_reset_comp_w(int which, int data)
  152. {
  153.     struct TTL74123 *c = chip + which;
  154.  
  155.     /* trigger=hi, trigger_comp=lo and rising edge on reset_comp */
  156.     if (data)
  157.         CHECK_TRIGGER(c->trigger && !c->trigger_comp && !c->reset_comp)
  158.     else
  159.         RESET
  160.  
  161.     c->reset_comp = data;
  162. }
  163.  
  164.  
  165. int TTL74123_output_r(int which)
  166. {
  167.     return chip[which].output;
  168. }
  169.  
  170.  
  171. int TTL74123_output_comp_r(int which)
  172. {
  173.     return !chip[which].output;
  174. }
  175.